package cn.zyq.ykb.controller.mgt.config;

import cn.zyq.ykb.beans.config.ConfigPackage;
import cn.zyq.ykb.service.config.ConfigPackageService;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 配置-下载安装包Controller
 *
 * @author SystemAuth
 * @date 2023-06-15
 */

@RestController(value = "MgtConfigPackageController")
@RequestMapping("/mgt/configPackage")
@Api(tags = "配置-下载安装包接口")
public class ConfigPackageController extends BaseController {

    @Autowired
    private ConfigPackageService configPackageService;

    /**
     * 查询配置-下载安装包列表
     */
    @ApiOperation(value = "列表", response = ConfigPackage.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.configPackageService.selectConfigPackageList(pageParam);
    }

     /**
      * 导出配置-下载安装包列表
      */
     @ApiOperation(value = "导出")
     @Log(title = "配置-下载安装包" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, @RequestBody PageParam pageParam) {
         List<ConfigPackage> list = configPackageService.selectConfigPackageAllList(pageParam);
         ExcelUtil<ConfigPackage> util = new ExcelUtil<ConfigPackage>(ConfigPackage. class);
         util.exportExcel(response, list, "配置-下载安装包数据");
     }

    /**
     * 获取配置-下载安装包详细信息
     */
    @ApiOperation(value = "详情", response = ConfigPackage.class)
    @GetMapping(value = "/{configPackageID}")
    public Object getInfo(@PathVariable("configPackageID") Integer configPackageID) {
        return this.configPackageService.selectConfigPackageByConfigPackageID(configPackageID);
    }
    /**
     * 获取配置-下载安装包详细信息
     */
    @ApiOperation(value = "详情", response = ConfigPackage.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.configPackageService.selectConfigPackageByServiceID(serviceID);
    }

    /**
     * 新增配置-下载安装包
     */
    @ApiOperation(value = "新增")
    @Log(title = "配置-下载安装包", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody ConfigPackage configPackage) {
        return this.configPackageService.insertConfigPackage(configPackage);
    }

    /**
     * 修改配置-下载安装包
     */
    @ApiOperation(value = "编辑")
    @Log(title = "配置-下载安装包", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody ConfigPackage configPackage) {
        return this.configPackageService.updateConfigPackage(configPackage);
    }

    /**
     * 删除配置-下载安装包
     */
    @ApiOperation(value = "删除")
    @Log(title = "配置-下载安装包", businessType = BusinessType.DELETE)
    @DeleteMapping("/{configPackageIDs}")
    public Object remove(@PathVariable Integer[] configPackageIDs) {
        return this.configPackageService.deleteConfigPackageByConfigPackageIDs(configPackageIDs);
    }

    /**
     * 可用不可用
     */
    @ApiOperation(value = "可用不可用")
    @GetMapping("/enableDisable/{configPackageIDs}/{type}")
    public Object enableDisable(@PathVariable Integer[] configPackageIDs,@PathVariable("type") Integer type) {
        return this.configPackageService.enableDisable(configPackageIDs,type,this.getLoginSysAdmin());
    }
}
